/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
// 递归左右子树，不断让sum减去当前节点的值。左右子树有一个返回true就找到了一条这样的路径
/**
 * @param {TreeNode} root
 * @param {number} targetSum
 * @return {boolean}
 */
 var hasPathSum = function (root, targetSum) {
    if (root === null) return false // 递归终止条件
    if (root.left === null && root.right === null) { // 遍历到叶子节点
      return (targetSum - root.val) === 0
    }
    // 递归左右子树
    return hasPathSum(root.left, targetSum - root.val) || hasPathSum(root.right, targetSum - root.val)
  };